﻿<%@ WebHandler Language="C#" Class="TestHandler" %>

using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using System.Linq;
using System.Collections;
using Newtonsoft.Json;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using System.Collections.Generic;
using System.Text;

//Description:工序的工区维护、工时维护、设备维护、生产周期处理程序
//Copyright (c) : 通力凯顿（北京）系统集成有限公司
//Writer:zhangrj
//create Date:2022-04-10
public class TestHandler : IHttpHandler, IRequiresSessionState
{
    CurrentUserInfo m_UserInfo;
    WorkFlowStepMaintBusiness workFlowStepMaint = new WorkFlowStepMaintBusiness();
    uLMSCommonBusiness commonBusiness = new uLMSCommonBusiness();
    uLMSStepTimeIBusiness stepTimeBusiness = uMESBusinessFactory.instance.GetuLMSStepTimeObject();
    uLMSContainercurrentinfoIBusiness m_ContainerCurrentInfoObj = uMESBusinessFactory.instance.GetuLMSContainerCurrentInfoObject();
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request["action"].ToString();
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            if (m_UserInfo == null)
            {
                context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "登录过期，请重新登录" }));
            }
            switch (action)
            {
                case "InitWorkCenterPage": //初始化工区维护页面
                    InitWorkCenterPage(context);
                    break;
                case "GetStepData"://获取工序列表数据
                    GetStepDatas(context);
                    break;
                case "GetStepTimeForOtherRev"://保存其他版本工艺数据
                    GetStepTimeForOtherRev(context);
                    break;
                case "GetResourceDatas"://搜索设备数据
                    GetResourceDatas(context);
                    break;
                case "GetStepResourceDatas"://获取工序设备数据
                    GetStepResourceDatas(context);
                    break;
                case "SaveStepWorkCenterInfo": //保存工序工区班组、工时信息、设备信息、生产周期、商品工时
                    SaveStepWorkCenterInfo(context);
                    break;
                case "GetSpecWorkTimeData": //实做工时传递
                    GetStepWorkTimeDatas(context);
                    break;


                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            var result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.ContentType = "text/html";
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    /// <summary>
    /// 搜索设备数据
    /// </summary>
    /// <param name="context"></param>
    public void GetResourceDatas(HttpContext context)
    {
        string resourceName = context.Request["resourceName"].ToString();
        string resourceNum = context.Request["resourceNum"].ToString();
        string strSql = @"SELECT r.resourceid,r.resourcename,r.description,r.factoryid,f.factoryname FROM resourcedef r 
                          LEFT JOIN Factory f ON f.factoryid = r.factoryid
                          where 1=1";
        if (!string.IsNullOrWhiteSpace(resourceName))//设备名不为空
        {
            strSql += String.Format(" and r.description like '{0}%'", resourceName);
        }
        if (!string.IsNullOrWhiteSpace(resourceNum))//设备编号不为空
        {
            strSql += String.Format(" and r.resourcename like '{0}%'", resourceNum);
        }
        if (context.Request["factoryId"] != null && !string.IsNullOrWhiteSpace(context.Request["factoryId"].ToString()))
        {
            strSql += String.Format(" and r.factoryid ='{0}'", context.Request["factoryId"].ToString());
        }
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(strSql);
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "获取成功", DBTable = dt }));
    }
    /// <summary>
    /// 获取工序设备数据
    /// </summary>
    /// <param name="context"></param>
    public void GetStepResourceDatas(HttpContext context)
    {
        string specIds = context.Request["specIds"].ToString();
        specIds = specIds.TrimEnd(',');
        DataTable dt = workFlowStepMaint.GetStepResourceDatas(specIds);
        context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "获取成功", DBTable = dt }));
    }

    /// <summary>
    /// 初始化工区维护页面
    /// </summary>
    /// <param name="context"></param>
    public void InitWorkCenterPage(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "查询完成" };
        string strRole_GYY = ""; //工艺员
        string strRole_JHY = ""; //计划员
        string strRole_GQZ = ""; //工区长
        strRole_GYY = commonBusiness.GetEnterpriseAttributes("工艺员角色");
        if (string.IsNullOrWhiteSpace(strRole_GYY))
        {
            strRole_GYY = "StepManageTFW";
        }
        strRole_JHY = commonBusiness.GetEnterpriseAttributes("计划员角色");
        if (string.IsNullOrWhiteSpace(strRole_JHY))
        {
            strRole_JHY = "StepManageTFW";
        }
        strRole_GQZ = commonBusiness.GetEnterpriseAttributes("工区长角色");
        if (string.IsNullOrWhiteSpace(strRole_GQZ))
        {
            strRole_GQZ = "StepManageTFW";
        }
        DataTable dtWorkCenter = new DataTable();
        if (m_UserInfo.Roles.Contains(strRole_GYY) || m_UserInfo.Roles.Contains(strRole_JHY) || m_UserInfo.Roles.Contains(strRole_GQZ))
        {
            dtWorkCenter = commonBusiness.GetWorkCenterByFacoryID(m_UserInfo.FactoryID, false);
        }
        result.DBTable = dtWorkCenter;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 获取工序数据
    /// </summary>
    /// <param name="context"></param>
    public void GetStepDatas(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "查询完成" };
        DataSet ds = new DataSet();
        string workflowId = context.Request["workflowId"].ToString();
        if (string.IsNullOrWhiteSpace(workflowId))
        {
            result.Result = false;
            result.Message = "没有工艺路线";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        DataTable dtStep = new DataTable();
        dtStep = workFlowStepMaint.GetWorkflowStepData(workflowId);
        //只显示自己分厂工序 add:Wangjh 20220315
        //DataRow[] temp = dtStep.Select("sfactoryid='" + m_UserInfo.FactoryID + "'");
        //if (temp.Length > 0)
        //{
        //    dtStep = temp.CopyToDataTable();
        //}
        //else
        //{
        //    dtStep.Rows.Clear();
        //}
        dtStep.Columns.Add("IsUpdateWorkcenter");//是否需要更新工区
        dtStep.Columns.Add("IsUpdateTime");//是否需要更新工时
        dtStep.Columns.Add("IsUpdateCycle");//是否需要更新生产周期
        dtStep.Columns.Add("IsUpdateCommodityTime");//是否需要更新商品工时
        dtStep.TableName = "dtStep";
        ds.Tables.Add(dtStep);
        /*选择其他版本的工艺路线时获取它的其他版本工艺路线*/
        if (bool.Parse(context.Request["isSomeWorkflow"].ToString()))//如果选择了同名工艺
        {
            DataTable workflowdt = commonBusiness.GetWorkflowInfobyWorkflowID(workflowId);
            DataTable dt = commonBusiness.GetWorkFlowOtherRevision(workflowId, workflowdt.Rows[0]["WORKFLOWBASEID"].ToString());
            if (dt.Select("isuse='0'").Length > 0)
            {
                dt = dt.Select("isuse='0'").CopyToDataTable();
            }
            else
            {
                dt.Rows.Clear();
            }
            dt.TableName = "dtOtherRevWF";
            ds.Tables.Add(dt);
            result.DBDataSet = ds;
        }
        else
        {
            bool isThisFactory = bool.Parse(context.Request["isThisFactory"].ToString());
            string productNames = context.Request["productName"].ToString();
            Dictionary<string, string> dic = new Dictionary<string, string>();
            string productName = productNames.Substring(0, productNames.IndexOf(":"));
            dic.Add("ProductName", productName);
            productNames = productNames.Replace(productName + ":", "");
            int len = productNames.IndexOf("(") == -1 ? productNames.Length : productNames.IndexOf("(");
            string productRev = productNames.Substring(0, len);
            dic.Add("ProductRev", productRev);
            if (isThisFactory)
            {
                dic.Add("FactoryID", m_UserInfo.FactoryID);
            }
            DataTable dt = commonBusiness.GetWorkflowInfoWithOtherAndSubByProductInfo(dic, false, isThisFactory);
            DataRow dr = dt.Select(string.Format("workflowid='{0}'", workflowId)).FirstOrDefault();
            if (dr != null)
            {
                dt.Rows.Remove(dr);
            }
            dt.TableName = "dtOtherRevWF";
            ds.Tables.Add(dt);
            result.DBDataSet = ds;
        }

        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 获取其他工艺版本的工序属性
    /// </summary>
    /// <param name="context"></param>
    public void GetStepTimeForOtherRev(HttpContext context)
    {
        string workflowId = context.Request["workflowId"].ToString();
        string otherRevWorkflowId = context.Request["otherRevWorkflowId"].ToString();
        DataTable dtStep = JsonConvert.DeserializeObject<DataTable>(context.Request["dtStep"].ToString());
        if (string.IsNullOrWhiteSpace(otherRevWorkflowId))
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "请选择其他工艺版本" }));
            return;
        }
        if (string.IsNullOrWhiteSpace(workflowId))
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "未选择工艺" }));
            return;
        }
        if (dtStep.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "没有工序" }));
            return;
        }
        DataTable resultDT = workFlowStepMaint.GetWorkflowStepData(otherRevWorkflowId);//查询其他版本工艺的工序
        DataTable dtStepRes = new DataTable();//工序设备关联表格
        dtStepRes.Columns.Add("RESOURCEID");
        dtStepRes.Columns.Add("SPECID");
        DataTable dtCopyStep = resultDT.Copy();//需要更改的工序
        dtCopyStep.Rows.Clear();
        foreach (DataRow item in dtStep.Rows)
        {
            DataRow dr = resultDT.Select(String.Format("WORKFLOWSTEPNAME='{0}'", item["WORKFLOWSTEPNAME"].ToString())).FirstOrDefault();
            if (dr != null)//与其他版本工艺的工序相同，则复制其属性
            {
                //查询出需要复制的工序设备
                DataTable dt = workFlowStepMaint.GetStepResourceDatas("'" + dr["SpecID"].ToString() + "'");
                foreach (DataRow srs in dt.Rows)
                {
                    DataRow drs = dtStepRes.NewRow();
                    drs["SPECID"] = item["SpecID"].ToString();
                    drs["RESOURCEID"] = srs["RESOURCEID"].ToString();
                    dtStepRes.Rows.Add(drs);
                }
                //将该工序改为需要更改的工序
                dr["WORKFLOWSTEPID"] = item["WORKFLOWSTEPID"].ToString();
                dtCopyStep.Rows.Add(dr.ItemArray);
            }
        }
        uMESProcessResult result = new uMESProcessResult();
        //保存工区
        uMESProcessResult res = workFlowStepMaint.SaveStepWorkCenterDatas(dtCopyStep, workflowId);
        result.Result = res.Result;
        result.Message += res.Message + ",";

        //m_ContainerCurrentInfoObj.UpdateProcessingContainerByWorkflow(workflowId); //add:Wangjh 20230424 此方法无误后，前面“更新总表工序所有工区和班组 add:Wangjh 20180611”可以取消

        //保存生产周期
        res = workFlowStepMaint.SaveStepCycleDatas(dtCopyStep);
        result.Result = result.Result ? res.Result : result.Result;//如果第一次出错，后续都是错
        result.Message += res.Message + ",";
        //保存工时
        bool resbool = stepTimeBusiness.UpdateStepTimeInfo(dtCopyStep, 0);//0代表更新工时
        result.Result = result.Result ? resbool : result.Result;
        result.Message += resbool ? "更新工时成功," : "更新工时失败";
        //保存设备
        res = workFlowStepMaint.CreateStepResourceData(dtStepRes);
        result.Result = result.Result ? res.Result : result.Result;
        result.Message += res.Message;
        result.Message = result.Result ? "属性获取成功" : result.Message;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 保存工序工区、工时、生产周期、设备数据
    /// </summary>
    /// <param name="context"></param>
    public void SaveStepWorkCenterInfo(HttpContext context)
    {
        DataTable dtStep = JsonConvert.DeserializeObject<DataTable>(context.Request["dtStep"].ToString());//选择的工序
        DataTable dtRes = JsonConvert.DeserializeObject<DataTable>(context.Request["dtRes"].ToString());//需要添加的设备
        string workflowId = context.Request["workflowId"].ToString();
        string deleResIds = context.Request["deleResIds"].ToString();//删除设备ID集
        if (string.IsNullOrWhiteSpace(workflowId))
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "没有选择工艺" }));
            return;
        }
        if (dtStep.Rows.Count == 0)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "没有选择保存的工序" }));
            return;
        }
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "" };
        DataTable dtWorkcenter = dtStep.Clone();//工区更新数据表
        DataTable dtTime = dtStep.Clone();//工时更新数据表
        DataTable dtCycle = dtStep.Clone();//生产周期更新数据表
        DataTable dtCommodityTime = dtStep.Clone();//商品工时更新数据表
        foreach (DataRow item in dtStep.Rows)
        {
            if (IsThreeFixedCardsForSpec(workflowId, item["specno"].ToString())) //验证工序是否是三定卡片
            {
                result.Result = false;
                result.Message = "工序:" + item["workflowStepName"].ToString() + "是三定卡片，不可编辑";
                break;
            }
            if (item["IsUpdateWorkcenter"].ToString() == "1") //如果是更新工区班组，则验证
            {
                if (VerifyStepDispatchInfoOfNotWorkReport(item["workflowStepId"].ToString()))
                {
                    result.Result = false;
                    result.Message = "工序:" + item["workflowStepName"].ToString() + "存在派工未报工记录";
                    break;
                }
                if (item["ControlCode"].ToString().Trim() == "LY05")
                {
                    result.Result = false;
                    result.Message = "工序:" + item["workflowStepName"].ToString() + "是固定外委序，不允许维护班组信息";
                    break;
                }
                if (string.IsNullOrWhiteSpace(item["wffactoryid"].ToString()))
                {
                    result.Result = false;
                    result.Message = "工序:" + item["workflowStepName"].ToString() + "所属工艺没有维护分厂属性";
                    break;
                }
                if (string.IsNullOrWhiteSpace(item["sfactoryid"].ToString()))
                {
                    result.Result = false;
                    result.Message = "工序:" + item["workflowStepName"].ToString() + "没有维护分厂属性";
                    break;
                }
                //if (m_UserInfo.FactoryID != item["sfactoryid"].ToString())
                //{
                //result.Result = false;
                //result.Message = "工序:" + item["workflowStepName"].ToString() + "是固定转工序，不允许维护班组信息";
                //break;
                //}
                if (m_UserInfo.FactoryID == item["sfactoryid"].ToString())//不是转工序，允许修改工区
                {
                    dtWorkcenter.Rows.Add(item.ItemArray);//添加到需更新工区班组的表中
                }
            }
            if (item["IsUpdateTime"].ToString() == "1")
            {
                dtTime.Rows.Add(item.ItemArray);//添加到需更新工时的表中
            }
            if (item["IsUpdateCycle"].ToString() == "1")
            {
                dtCycle.Rows.Add(item.ItemArray);//添加到需要更新工序生产周期表中
            }
            if (item["IsUpdateCommodityTime"].ToString() == "1")
            {
                dtCommodityTime.Rows.Add(item.ItemArray);//添加到需要更新商品工时表中
            }
        }
        if (result.Result)//验证成功才保存
        {
            if (dtWorkcenter.Rows.Count > 0)//工区班组表不为空，更新工区班组
            {
                uMESProcessResult res = workFlowStepMaint.SaveStepWorkCenterDatas(dtWorkcenter, workflowId);
                result.Result = res.Result;
                result.Message += res.Message + ",";
            }
            if (dtTime.Rows.Count > 0 && result.Result)//工时不为空，更新工时
            {
                result.Result = stepTimeBusiness.UpdateStepTimeInfo(dtTime, 0);//0代表更新工时
                result.Message += result.Result ? "更新工时成功," : "更新工时失败";
            }
            if (!string.IsNullOrWhiteSpace(deleResIds) && result.Result)//删除设备
            {
                deleResIds = deleResIds.TrimEnd(',');
                uMESProcessResult res = workFlowStepMaint.DeleteStepResourceData(deleResIds);
                result.Result = res.Result;
                result.Message += res.Message + ",";
            }
            if (dtRes.Rows.Count > 0 && result.Result)//如果工序设备不为空，插入
            {
                uMESProcessResult res = workFlowStepMaint.CreateStepResourceData(dtRes);
                result.Result = res.Result;
                result.Message += res.Message + ",";
            }
            if (dtCycle.Rows.Count > 0 && result.Result) //如果生产周期不为空，则更新
            {
                uMESProcessResult res = workFlowStepMaint.SaveStepCycleDatas(dtCycle);
                result.Result = res.Result;
                result.Message += res.Message + ",";
            }
            if (dtCommodityTime.Rows.Count > 0 && result.Result) //如果商品工时不为空，则更新
            {
                uMESProcessResult res = workFlowStepMaint.SaveStepCommodityTimeDatas(dtCommodityTime, workflowId, m_UserInfo);
                result.Result = res.Result;
                result.Message += res.Message;
            }
            result.Message = result.Result ? "保存成功" : result.Message.TrimEnd(',');
        }
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 验证工序是否有派工未报工的记录存在
    /// </summary>
    /// <param name="workflowStepId"></param>
    /// <returns></returns>
    private bool VerifyStepDispatchInfoOfNotWorkReport(string workflowStepId)
    {
        DataTable dt = stepTimeBusiness.VerifyStepDispatchInfoOfNotWorkReport(workflowStepId);
        return dt.Rows.Count > 0 ? true : false;
    }

    /// <summary>
    /// 验证工序是否是三定卡片
    /// </summary>
    /// <param name="workflowID"></param>
    /// <param name="specNO"></param>
    /// <returns></returns>
    private bool IsThreeFixedCardsForSpec(string workflowID, string specNO)
    {
        string sql = string.Format(@"SELECT 1 FROM Workflow w 
                        LEFT JOIN workflowbase wb ON wb.workflowbaseid = w.workflowbaseid
                        INNER JOIN ThreeFixedCards tc ON tc.workflowname = wb.workflowname 
                                AND tc.workflowversion = w.workflowrevision AND tc.specno = '{0}'
                        WHERE w.workflowid = '{1}'", specNO, workflowID);
        if (DatabaseHelper.GetSingle(sql) != null)
        {
            return true;
        }
        return false;
    }

    /// <summary>
    /// 实做工时传递 add by duht 
    /// 查询优化：zhangrj 20241231
    /// </summary>
    /// <param name="context"></param>
    public void GetStepWorkTimeDatas(HttpContext context)
    {
        uMESProcessResult result = new uMESProcessResult() { Result = true, Message = "查询完成" };
        string workflowId = context.Request["workflowId"].ToString();
        string[] specids = context.Request["specids"].ToString().Split(',');

        string workflowstepIDs = context.Request["specids"].ToString().Replace(",", "','");

        if (string.IsNullOrWhiteSpace(workflowId))
        {
            result.Result = false;
            result.Message = "没有工艺路线";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }

        StringBuilder sb = new StringBuilder();
        /*选择其他版本的工艺路线时获取它的其他版本工艺路线*/
        if (bool.Parse(context.Request["isSomeWorkflow"].ToString()))//如果选择了同名工艺
        {
            //dtStep = commonBusiness.GetWorkFlowOtherVersionAndSonSPec(workflowId); //原始查询较慢，优化查询逻辑，如下：
            sb.AppendLine(@" SELECT  s.specid,CASE WHEN s.specno = '0000' THEN '0001' ELSE s.specno END specno,
                            sb.specname,s1.specno AS sonspecno,pb.productname,wfs.MakeCycle, p.description,w.workflowid,w.workflowbaseid  
                            FROM WORKFLOWSTEP wfs ");
            sb.AppendLine(" LEFT JOIN Workflow w ON w.workflowid=wfs.workflowid ");
            sb.AppendLine("LEFT JOIN specbase sb ON wfs.specbaseid=sb.specbaseid ");
            sb.AppendLine(" LEFT JOIN spec s ON s.specid = nvl(sb.revofrcdid,wfs.specid) ");
            sb.AppendLine(" LEFT JOIN stepsubstep sp ON sp.workflowstepid =wfs.workflowstepid  ");
            sb.AppendLine(" LEFT JOIN Workflowstep wfs1 ON wfs1.workflowstepid=sp.sonworkflowstepid  ");
            sb.AppendLine(" LEFT JOIN specbase sb1 ON sb1.specbaseid=wfs1.specbaseid  ");
            sb.AppendLine(" LEFT JOIN spec s1 ON s1.specid = nvl(sb1.revofrcdid,wfs1.specid) ");
            sb.AppendLine("LEFT JOIN product p ON p.productid=w.productid ");
            sb.AppendLine("LEFT JOIN productbase pb ON pb.productbaseid=p.productbaseid ");
            sb.AppendFormat(" WHERE wfs.workflowstepid IN ('{0}') AND EXISTS( SELECT 1 FROM Workflow ww WHERE ww.workflowid= '{0}' AND ww.workflowbaseid=w.workflowbaseid)  ", workflowstepIDs, workflowId);
        }
        else
        {
            //dtStep = commonBusiness.GetWorkFlowAndSonSPec(workflowId); //原始查询较慢，优化查询逻辑，如下：
            sb.AppendLine(@" SELECT  s.specid,CASE WHEN s.specno = '0000' THEN '0001' ELSE s.specno END specno,
                            sb.specname,s1.specno AS sonspecno,pb.productname,wfs.MakeCycle, p.description,w.workflowid,w.workflowbaseid  
                            FROM WORKFLOWSTEP wfs ");
            sb.AppendLine(" LEFT JOIN Workflow w ON w.workflowid=wfs.workflowid ");
            sb.AppendLine("LEFT JOIN specbase sb ON wfs.specbaseid=sb.specbaseid ");
            sb.AppendLine(" LEFT JOIN spec s ON s.specid = nvl(sb.revofrcdid,wfs.specid) ");
            sb.AppendLine(" LEFT JOIN stepsubstep sp ON sp.workflowstepid =wfs.workflowstepid  ");
            sb.AppendLine(" LEFT JOIN Workflowstep wfs1 ON wfs1.workflowstepid=sp.sonworkflowstepid  ");
            sb.AppendLine(" LEFT JOIN specbase sb1 ON sb1.specbaseid=wfs1.specbaseid  ");
            sb.AppendLine(" LEFT JOIN spec s1 ON s1.specid = nvl(sb1.revofrcdid,wfs1.specid) ");
            sb.AppendLine("LEFT JOIN product p ON p.productid=w.productid ");
            sb.AppendLine("LEFT JOIN productbase pb ON pb.productbaseid=p.productbaseid ");
            sb.AppendFormat(" WHERE wfs.workflowstepid IN ('{0}')", workflowstepIDs);
        }
        DataTable dtStep = DatabaseHelper.Query_ReturnDatTable(sb.ToString());
        //DataTable dtTemp = dtStep.Clone();
        //for (int i = 0; i < dtStep.Rows.Count; i++)
        //{
        //    if (specids.Contains(dtStep.Rows[i]["specid"].ToString()))
        //    {
        //        dtTemp.Rows.Add(dtStep.Rows[i].ItemArray);
        //    }
        //}
        //dtTemp.AcceptChanges();
        MESToESB.ESBInterface esb = new MESToESB.ESBInterface();
        esb.send_workHour_Recive(dtStep);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
}